<?php
	class InteretsProManager{
		  private $_db;
	
		  public function __construct($db){
				$this->setDb($db);
		  }
		  
		  public function setDb(PDO $db){
				$this->_db = $db;
		  }
		  
		  public function add(InteretsPro $interetspro){// permet d'ajouter une question
				$q = $this->_db->prepare('INSERT INTO interetspro SET classement = :classement, idRefEleve = :idRefEleve, idRefReponse = :idRefReponse');
				$q->bindValue(':classement', $interetspro->classement());
				$q->bindValue(':idRefEleve', $interetspro->idRefEleve());
				$q->bindValue(':idRefReponse', $interetspro->idRefReponse());
				$q->execute();
		  }
		  
		  public function delete(InteretsPro $interetspro){// permet de supprimer une question
			  $this->_db->exec('DELETE FROM interetspro WHERE id = '.$interetspro->id());
		  }
		  
		  public function update(InteretsPro $interetspro){// permet de modifier une question
				$q = $this->_db->prepare('UPDATE interetspro SET idRefEleve = :idRefEleve, idRefReponse = :idRefReponse, classement = :classement WHERE id ='.$interetspro->id());
				$q->bindValue(':idRefEleve', $interetspro->idRefEleve());
				$q->bindValue(':idRefReponse', $interetspro->idRefReponse());
				$q->bindValue(':classement', $interetspro->classement());
				$q->execute();
		  }
		  
		  public function get($id){// retourne l'objet question d'id correspondant
				$id = (int) $id;
				$q = $this->_db->query('SELECT * FROM interetspro WHERE id = '.$id);
				$donnees = $q->fetch();
				return new InteretsPro($donnees);
		  }
		  
		  public function getGroupByEleve(){
			  $interetspro = array();
			  $q = $this->_db->query('SELECT * FROM interetspro GROUP BY idRefEleve');
			  while($donnees = $q->fetch())
			  {
				  $interetspro[] = new InteretsPro($donnees);
			  }
			  return $interetspro;
		  }
		  
		  public function getByEleve($idEleve){
			  $interetspro = array();
			  $q = $this->_db->query('SELECT * FROM interetspro WHERE idRefEleve = '.$idEleve);
			  while($donnees = $q->fetch())
			  {
				  $interetspro[] = new InteretsPro($donnees);
			  }
			  return $interetspro;
		  }
		  
		  public function getClassement($idEleve, $idReponse){
			  $q = $this->_db->query('SELECT * FROM interetspro WHERE idRefEleve = '.$idEleve.' AND idRefReponse = '.$idReponse);
			  $donnees = $q->fetch();
			  return new InteretsPro($donnees);
		  }
	}
?>